/**
 * 通知管理相关API
 */

import api from './request'

// 消息管理API
export const messageApi = {
  // 发送消息
  sendMessage: (data) => {
    return api.post('/notification/message/send', data)
  },

  // 批量发送消息
  sendBatchMessages: (data) => {
    return api.post('/notification/message/send/batch', data)
  },

  // 分页查询接收的消息
  getReceivedMessages: (params) => {
    return api.get('/notification/message/received', { params })
  },

  // 分页查询发送的消息
  getSentMessages: (params) => {
    return api.get('/notification/message/sent', { params })
  },

  // 标记消息为已读
  markAsRead: (messageId, receiverId) => {
    return api.put(`/notification/message/read/${messageId}`, null, {
      params: { receiverId }
    })
  },

  // 批量标记消息为已读
  markBatchAsRead: (messageIds, receiverId) => {
    return api.put('/notification/message/read/batch', messageIds, {
      params: { receiverId }
    })
  },

  // 获取未读消息数量
  getUnreadCount: (receiverId) => {
    return api.get('/notification/message/unread/count', {
      params: { receiverId }
    })
  },

  // 删除消息
  deleteMessage: (messageId, userId) => {
    return api.delete(`/notification/message/${messageId}`, {
      params: { userId }
    })
  },

  // 批量删除消息
  deleteBatchMessages: (messageIds, userId) => {
    return api.delete('/notification/message/batch', {
      data: messageIds,
      params: { userId }
    })
  },

  // 获取消息详情
  getMessage: (messageId) => {
    return api.get(`/notification/message/${messageId}`)
  }
}

// 通知管理API
export const notificationApi = {
  // 发送站内信
  sendStationMessage: (data) => {
    return api.post('/notification/notification/station-message', data)
  },

  // 批量发送站内信
  sendBatchStationMessages: (data) => {
    return api.post('/notification/notification/station-message/batch', data)
  },

  // 发送实时消息
  sendRealTimeMessage: (userId, message) => {
    return api.post('/notification/notification/realtime-message', null, {
      params: { userId, message }
    })
  },

  // 批量发送实时消息
  sendBatchRealTimeMessages: (userIds, message) => {
    return api.post('/notification/notification/realtime-message/batch', userIds, {
      params: { message }
    })
  },

  // 发送短信
  sendSms: (phoneNumber, templateCode, templateParams) => {
    return api.post('/notification/notification/sms', templateParams, {
      params: { phoneNumber, templateCode }
    })
  },

  // 批量发送短信
  sendBatchSms: (phoneNumbers, templateCode, templateParams) => {
    return api.post('/notification/notification/sms/batch', phoneNumbers, {
      params: { templateCode },
      data: templateParams
    })
  },

  // 发送邮件
  sendEmail: (to, subject, content) => {
    return api.post('/notification/notification/email', null, {
      params: { to, subject, content }
    })
  },

  // 批量发送邮件
  sendBatchEmails: (toList, subject, content) => {
    return api.post('/notification/notification/email/batch', toList, {
      params: { subject, content }
    })
  },

  // 发送模板邮件
  sendTemplateEmail: (to, templateCode, templateParams) => {
    return api.post('/notification/notification/email/template', templateParams, {
      params: { to, templateCode }
    })
  },

  // 广播系统消息
  broadcastSystemMessage: (message) => {
    return api.post('/notification/notification/broadcast', null, {
      params: { message }
    })
  },

  // 发送消息到用户组
  sendToUserGroup: (groupId, message) => {
    return api.post(`/notification/notification/group/${groupId}`, null, {
      params: { message }
    })
  }
}

// 消息模板API
export const messageTemplateApi = {
  // 获取消息模板列表
  getTemplates: (params) => {
    return api.get('/notification/message-template/list', { params })
  },

  // 创建消息模板
  createTemplate: (data) => {
    return api.post('/notification/message-template/add', data)
  },

  // 更新消息模板
  updateTemplate: (data) => {
    return api.put('/notification/message-template/update', data)
  },

  // 删除消息模板
  deleteTemplate: (id) => {
    return api.delete(`/notification/message-template/${id}`)
  },

  // 获取消息模板详情
  getTemplate: (id) => {
    return api.get(`/notification/message-template/${id}`)
  },

  // 启用模板
  enableTemplate: (id) => {
    return api.put(`/notification/message-template/enable/${id}`)
  },

  // 禁用模板
  disableTemplate: (id) => {
    return api.put(`/notification/message-template/disable/${id}`)
  },

  // 渲染模板
  renderTemplate: (templateCode, params) => {
    return api.post(`/notification/message-template/render/${templateCode}`, params)
  }
}

// 默认导出所有API
export default {
  messageApi,
  notificationApi,
  messageTemplateApi
} 